/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package utn.frsf.cidisi.upcolbpip.interactionprotocols.impl;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.ecore.EClass;

import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;

import utn.frsf.cidisi.upcolbpip.interactionprotocols.InteractionprotocolsPackage;
import utn.frsf.cidisi.upcolbpip.interactionprotocols.Lifeline;
import utn.frsf.cidisi.upcolbpip.interactionprotocols.Termination;
import utn.frsf.cidisi.upcolbpip.interactionprotocols.TerminationElement;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Termination</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link utn.frsf.cidisi.upcolbpip.interactionprotocols.impl.TerminationImpl#getTerminationElement <em>Termination Element</em>}</li>
 *   <li>{@link utn.frsf.cidisi.upcolbpip.interactionprotocols.impl.TerminationImpl#getLifeline <em>Lifeline</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class TerminationImpl extends InteractionProtocolElementImpl implements Termination {
	/**
	 * The default value of the '{@link #getTerminationElement() <em>Termination Element</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTerminationElement()
	 * @generated
	 * @ordered
	 */
	protected static final TerminationElement TERMINATION_ELEMENT_EDEFAULT = TerminationElement.SUCCESS;

	/**
	 * The cached value of the '{@link #getTerminationElement() <em>Termination Element</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTerminationElement()
	 * @generated
	 * @ordered
	 */
	protected TerminationElement terminationElement = TERMINATION_ELEMENT_EDEFAULT;

	/**
	 * The cached value of the '{@link #getLifeline() <em>Lifeline</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLifeline()
	 * @generated
	 * @ordered
	 */
	protected Lifeline lifeline;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected TerminationImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return InteractionprotocolsPackage.Literals.TERMINATION;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public TerminationElement getTerminationElement() {
		return terminationElement;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTerminationElement(TerminationElement newTerminationElement) {
		TerminationElement oldTerminationElement = terminationElement;
		terminationElement = newTerminationElement == null ? TERMINATION_ELEMENT_EDEFAULT : newTerminationElement;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, InteractionprotocolsPackage.TERMINATION__TERMINATION_ELEMENT, oldTerminationElement, terminationElement));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Lifeline getLifeline() {
		if (lifeline != null && lifeline.eIsProxy()) {
			InternalEObject oldLifeline = (InternalEObject)lifeline;
			lifeline = (Lifeline)eResolveProxy(oldLifeline);
			if (lifeline != oldLifeline) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, InteractionprotocolsPackage.TERMINATION__LIFELINE, oldLifeline, lifeline));
			}
		}
		return lifeline;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Lifeline basicGetLifeline() {
		return lifeline;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setLifeline(Lifeline newLifeline) {
		Lifeline oldLifeline = lifeline;
		lifeline = newLifeline;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, InteractionprotocolsPackage.TERMINATION__LIFELINE, oldLifeline, lifeline));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case InteractionprotocolsPackage.TERMINATION__TERMINATION_ELEMENT:
				return getTerminationElement();
			case InteractionprotocolsPackage.TERMINATION__LIFELINE:
				if (resolve) return getLifeline();
				return basicGetLifeline();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case InteractionprotocolsPackage.TERMINATION__TERMINATION_ELEMENT:
				setTerminationElement((TerminationElement)newValue);
				return;
			case InteractionprotocolsPackage.TERMINATION__LIFELINE:
				setLifeline((Lifeline)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case InteractionprotocolsPackage.TERMINATION__TERMINATION_ELEMENT:
				setTerminationElement(TERMINATION_ELEMENT_EDEFAULT);
				return;
			case InteractionprotocolsPackage.TERMINATION__LIFELINE:
				setLifeline((Lifeline)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case InteractionprotocolsPackage.TERMINATION__TERMINATION_ELEMENT:
				return terminationElement != TERMINATION_ELEMENT_EDEFAULT;
			case InteractionprotocolsPackage.TERMINATION__LIFELINE:
				return lifeline != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (terminationElement: ");
		result.append(terminationElement);
		result.append(')');
		return result.toString();
	}

} //TerminationImpl
